package com.woniuxy.controller;

import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacManagerService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 罗蔚
 * @Date 2022/4/14 16:31
 * @Description TODO
 */
@RestController
@RequestMapping("/rbacManager")
public class RbacManagerController {
    @Autowired
    RbacManagerService rbacManagerService;
    @PostMapping("/manager")
    public ResponseEntity addOne(@RequestBody RbacManager rbacManager){
        return rbacManagerService.addOne(rbacManager);
    }

    @DeleteMapping("/manager/{id}")
    public ResponseEntity deleteOne(@PathVariable int id){
        return rbacManagerService.deleteOne(id);
    }

    @PutMapping("/manager")
    public ResponseEntity updateOne(@RequestBody RbacManager rbacManager){
        return rbacManagerService.updateOne(rbacManager);
    }

    @GetMapping("/manager/{id}")
    public ResponseEntity findOne(@PathVariable int id){
        return rbacManagerService.findOne(id);
    }
    @RequestMapping("/findAll")
    public ResponseEntity findAll() {
        return rbacManagerService.findAll();
    }

    @RequestMapping("/findAll/{currentPage}/{pageSize}")
    public ResponseEntity findAll(@PathVariable int currentPage, @PathVariable int pageSize) {
        return rbacManagerService.findAll(currentPage,pageSize);
    }

    @PostMapping("/manager/search")
    public ResponseEntity findLike(@RequestBody RbacManager rbacManager){
        return rbacManagerService.findLike(rbacManager);
    }

    @RequestMapping("/testRole")
    //这个controller方法，需要一个角色，才允许你访问我的controller
    @RequiresRoles("普通员工")
    public ResponseEntity testRole() {
        return new ResponseEntity(200, "拥有普通员工的权限，才能查出这句话", null);
    }

    @RequestMapping("/testPerm")
    //这个controller方法，需要一个角色，才允许你访问我的controller
    @RequiresPermissions(value = {"perm:list", "perm:update"}, logical = Logical.OR)
    public ResponseEntity testPerm() {
        return new ResponseEntity(200, "拥有list或update的权限，才能查出这句话", null);
    }

}
